<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const fn = function () {
        let b=1
        for (;;) {
          const uname = prompt("请输入用户名");
          const unm = prompt("请输入密码");

          let loginList = [
            { userName: "admin", password: "admin321" },
            { userName: "zhangsan", password: "zs321" },
            { userName: "lisi", password: "ls321" },
            { userName: "yyqx", password: "yyqx321" },
          ];
          let userInfo = {
            token1: {
              city: "杭州",
              money: "1000w",
              sex: "女",
              userName: "admin",
              password: "admin321",
            },
            token2: {
              city: "北京",
              money: "1100w",
              sex: "女",
              userName: "zhangsan",
              password: "zs321",
            },
            token3: {
              city: "北京",
              money: "800w",
              sex: "男",
              userName: "lisi",
              password: "ls321",
            },
            token4: {
              city: "天津",
              money: "600w",
              sex: "男",
              userName: "yyqx",
              password: "yyqx321",
            },
          };

          for (let i = 0; i < loginList.length; i++) {
            if (
              uname === loginList[i].userName &&
              unm === loginList[i].password
            ) {
              const sum = Math.floor(Math.random() * loginList.length + 1);
              let token = "token";
              token += sum;
              for (let key in userInfo) {
                if (token === key) {
                  userInfo[key].userName = uname;
                  userInfo[key].password = unm;
                  const obj = userInfo[key];
                  // console.log(obj);
                  alert(`
                     登录信息成功
                     ${"city:" + obj.city}
                     ${"money:" + obj.money}
                     ${"sex:" + obj.sex}
                     ${"userName:" + obj.userName}`);

                  return;
                } else {
                  continue;
                }
                return;
              }
              // console.log(loginList[i]);
              return;
            }
        }
        for (let i = 0; i < loginList.length; i++) {
            if (
              uname === loginList[i].userName &&
              unm === loginList[i].password
            ) {
              const sum = Math.floor(Math.random() * loginList.length + 1);
              let token = "token";
              token += sum;
              for (let key in userInfo) {
                if (token === key) {
                  userInfo[key].userName = uname;
                  userInfo[key].password = unm;
                  const obj = userInfo[key];
                  // console.log(obj);
                  alert(`
                     登录信息成功
                     ${"city:" + obj.city}
                     ${"money:" + obj.money}
                     ${"sex:" + obj.sex}
                     ${"userName:" + obj.userName}`);

                  return;
                } else {
                  continue;
                }
                return;
              }
              // console.log(loginList[i]);
              return;
            }
            
            // 输入错误的时候
            else {
              const arr = {};
              const add = +prompt(`
              该账号不存在
              1.注册账号 
              2.退出`);
              switch (add) {
                case 1:
                  const ass = prompt("请输入注册的账号");
                  const zxx = prompt("请输入注册的密码");
                  arr.userName = ass;
                  arr.password = zxx;
                  loginList.push(arr);
                  //   console.log(loginList);
                  for(;;){
                      
                      if(b !==0){
                        const uname = prompt("请输入用户名");
                        const unm = prompt("请输入密码");
                        b--
                        for(let a = 0; a < loginList.length; a++) {
                            if(uname === loginList[a].userName && unm === loginList[a].password){
                                const sum = Math.floor(Math.random() * loginList.length + 1)
                                let token = "token"
                                token += sum
                                for (let key in userInfo) {
                                    if (token === key) {
                                        userInfo[key].userName = uname;
                                        userInfo[key].password = unm;
                                        const obj = userInfo[key];
                                        alert(`
                                        登录信息成功
                                        ${"city:" + obj.city}
                                        ${"money:" + obj.money}
                                        ${"sex:" + obj.sex}
                                        ${"userName:" + obj.userName}
                                        `)
                                        return
                                    }
                                    
                                }
                            
                            }
                            
                        } 
                        continue

                    }else{
                        alert(`再次输入错误，已经没有机会了，退出了`)
                        return
                    }

                  }

                  break;
                case 2:
                  return;
                  default: {
                    continue
                  }
              }

              return;
            }
            return;
          }
        }
      };

      fn();
    </script>
  </body>
</html>
